package com.alibaba.ai.controller;

import com.alibaba.ai.service.ZHousingService;
import com.alibaba.ai.util.zHousingDTO;
import com.alibaba.ai.util.zHousingIdDTO;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by admin on 2020/5/28.
 */
@Controller
@RequestMapping("/ZF")
public class zHousingController {


    @Resource
    private ZHousingService zHousingService;


    @ResponseBody
    @GetMapping("/GR")//====================================================================================个人房源
    public JSONObject zHousingGR() {
        List<zHousingDTO> zHousingDTOGR = zHousingService.getzHousingDTOGR();//房源类型为住宅的为个人房源
        for (zHousingDTO dto : zHousingDTOGR) {
            System.err.println("lll" + dto);
        }

        JSONObject zHousingGR = new JSONObject();
        zHousingGR.put("zHousingGR", zHousingDTOGR);

        return zHousingGR;
    }


    @ResponseBody
    @GetMapping("/JX")//====================================================================================精选房源
    public JSONObject zHousingJX() {
        List<zHousingDTO> zHousingDTOJX = zHousingService.getzHousingDTOJX();//房源装修程度为精装修和豪华装修
        for (zHousingDTO dto : zHousingDTOJX) {
            System.err.println("con" + dto);
        }
        JSONObject zHousingJX = new JSONObject();
        zHousingJX.put("zHousingJX", zHousingDTOJX);
        return zHousingJX;
    }


    @ResponseBody
    @GetMapping("/index")
//====================================================================================首页遍历显示房源一些信息
    public JSONObject zHousing() {
        List<zHousingDTO> zHousingDTO = zHousingService.getzHousingDTOBy();

        JSONObject zHousing = new JSONObject();
        zHousing.put("zHousing", zHousingDTO);//按顺序排序储存或输出
        return zHousing;//测试成功
    }


    @ResponseBody
    @GetMapping("/index/{id}")
//====================================================================================进入房源信息展示界面
    public JSONObject zHousingId(@PathVariable(name = "id") Integer id) {
        zHousingIdDTO zHousingIdDTO = zHousingService.getzhousingIdDTO(id);//根据id查房源
        JSONObject zHousingId = new JSONObject();
        zHousingId.put("zHousingId", zHousingIdDTO);//按顺序排序储存或输出
        return zHousingId;
    }


    @ResponseBody
    @GetMapping("/GJ")//====================================================================================公交模糊查询
    public JSONObject zHousingGJ(@Param("in") String in) {
        /*in = "花园";*/
        String ins = "%" + in + "%";//模拟前端输入的值加拼接
        List<zHousingDTO> zHousingDTOGJ = zHousingService.getzHousingDTOGJ(ins);//根据 ins 模糊查询
        JSONObject zHousingGJ = new JSONObject();
        zHousingGJ.put("zHousingGJ", zHousingDTOGJ);//按顺序排序储存或输出
        return zHousingGJ;//测试成功
    }


    @ResponseBody
    @GetMapping("/GJZ")//====================================================================================关键字查询
    public JSONObject zHousingGJZ(@Param("Z_AREA") String Z_AREA, @Param("Z_ILLAGE") String Z_ILLAGE) {
        /*String Z_AREA = "";//区域（金水 Z_SITE 表中 ）
        String Z_ILLAGE = "正";//小区名（Z_HOUSING 表中）*/
        List<zHousingDTO> zHousingDTOGJX = zHousingService.getzHousingDTOGJZ(Z_AREA, Z_ILLAGE);//根据关键字查询
        JSONObject zHousingGJZ = new JSONObject();
        zHousingGJZ.put("zHousingGJZ", zHousingDTOGJX);
        return zHousingGJZ;
    }


    @ResponseBody
    @RequestMapping("/QY")//====================================================================================区域多条件查询
    public JSONObject zHousingQY(@Param("Z_AREA") String Z_AREA, @Param("Z_RENT1") String Z_RENT1, @Param("Z_RENT2") String Z_RENT2, @Param("Z_HOUSE") String Z_HOUSE, @Param("Z_MODE") String Z_MODE, @Param("Z_TOWARDS") String Z_TOWARDS) {
             /* Z_AREA = "";//区域
                Z_RENT1 = "";//租金1
                Z_RENT2 = "";//租金2
                Z_HOUSE = "";//户型(按照卧室算的)
                Z_MODE = "";//方式
                Z_TOWARDS = "";//朝向*/
        List<zHousingDTO> zHousingDTOQY = zHousingService.getzHousingDTOQY(Z_AREA, Z_RENT1, Z_RENT2, Z_HOUSE, Z_MODE, Z_TOWARDS);
        //根据条件模糊查询
        for (zHousingDTO dto : zHousingDTOQY) {
            System.err.println("con+++" + dto.getzTitle());
        }
        JSONObject zHousingQY = new JSONObject();
        zHousingQY.put("zHousingQY", zHousingDTOQY);
        return zHousingQY;
    }


    @ResponseBody
    @GetMapping("/DT")//====================================================================================地铁多条件查询
    public JSONObject zHousingDT(@Param("Z_SUBWAY") String Z_SUBWAY, @Param("Z_STATION") String Z_STATION, @Param("Z_DISTANCE1") String Z_DISTANCE1, @Param("Z_DISTANCE2") String Z_DISTANCE2, @Param("Z_RENT1") String Z_RENT1, @Param("Z_RENT2") String Z_RENT2, @Param("Z_HOUSE") String Z_HOUSE, @Param("Z_MODE") String Z_MODE, @Param("Z_TOWARDS") String Z_TOWARDS) {
        /*String Z_SUBWAY = "";//地铁线路
        String Z_STATION = "";//地铁站名
        String Z_DISTANCE1 = "";//距离1
        String Z_DISTANCE2 = "";//距离2
        String Z_RENT1 = "";//租金1
        String Z_RENT2 = "";//租金2
        String Z_HOUSE = "";//户型(按照卧室算的)
        String Z_MODE = "";//方式
        String Z_TOWARDS = "";//朝向*/
        List<zHousingDTO> zHousingDTODT = zHousingService.getzHousingDTODT(Z_SUBWAY, Z_STATION, Z_DISTANCE1,
                Z_DISTANCE2, Z_RENT1, Z_RENT2, Z_HOUSE, Z_MODE, Z_TOWARDS);//根据地铁信息查询房源
        JSONObject zHousingDT = new JSONObject();
        zHousingDT.put("zHousingDT", zHousingDTODT);

        return zHousingDT;
    }


}
